import { identity, pickBy, isNumber } from 'lodash';
import request from '@/http/request';
import { IQueryParams } from '@/widgets/table-pagination';

export function getList(queryParams: IQueryParams) {
  let params: any = {
    ...queryParams,
    pageNo: queryParams.pageNum,
    ...pickBy(queryParams.filter, identity),
    ...pickBy(queryParams.filter, isNumber),
  };
  delete params.pageNum;

  return request.get(
    `/admin-api/system/role/page?${new URLSearchParams(params)}`
  );
}

export function getSystemAppList() {
  return request.get(`/admin-api/system/app/group`);
}

export function getAppMenuList(key: any) {
  let params: any = {
    appId: key,
  };
  return request.get(
    `/admin-api/system/menu/app-menu-tree?${new URLSearchParams(params)}`
  );
}

export function fetchItem(key: any) {
  return request.get(`/admin-api/system/role/get?id=${key}`);
}

export function createItem(entity: any) {
  return request.post(`/admin-api/system/role/create`, entity);
}

export function updateItem(entity: any) {
  return request.put(`/admin-api/system/role/update`, entity);
}

export function deleteItem(key: any) {
  return request.delete(`/admin-api/system/role/delete?id=${key}`);
}
